<%@ include file="common/taglibs.jsp"%>
<stripes:layout-render name="/common/defaultLayout.jsp" titleKey="edit.categories.title">
	<stripes:layout-component name="content">

		<c:set var="categories" value="<%=org.yabam.model.Category.getAll()%>" />

		<div class="message">
			<h1><fmt:message key="edit.categories.head" bundle="${yabamResources}"/></h1>
			<p><fmt:message key="edit.categories.message" bundle="${yabamResources}"/></p>
		</div>
        <stripes:errors action="/EditCategories.action"/>
		<stripes:form action="/EditCategories.action">
			<table>
				<thead>
					<tr>
						<th></th>
						<th><fmt:message key="edit.categories.name" bundle="${yabamResources}"/></th>
						<th><fmt:message key="edit.categories.parent" bundle="${yabamResources}"/></th>
						<th/>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${categories}" var="category" varStatus="loop">
						<tr>
							<td><stripes:checkbox name="selectedCategories[${loop.index}].id" value="${category.id}"/>
							<td>${category.name}</td>
							<td>${category.parent.name}</td>
							<td><fmt:message key="edit.edit" bundle="${yabamResources}"/>
						</tr>
					</c:forEach>
				</tbody>
				<tfoot>
					<tr>
						<td colspan="4">
							<stripes:submit name="delete"><fmt:message key="edit.delete" bundle="${yabamResources}"/></stripes:submit>
						</td>
					</tr>
				</tfoot>
			</table>
			<div class="addBlock">
				<h1><fmt:message key="edit.categories.add" bundle="${yabamResources}"/></h1>
				<stripes:hidden name="category.id"/>
				<stripes:label for="category.name"/> : <stripes:text name="category.name"/>
				<br/>
				<stripes:label for="category.parent.id"/> : <stripes:select name="category.parent.id">
					<option/>
					<stripes:options-collection collection="${categories}" value="id" label="name"/>
				</stripes:select>
				<br/>
				<stripes:submit name="addOrEdit"><fmt:message key="edit.save" bundle="${yabamResources}"/></stripes:submit>
			</div>
		</stripes:form>
	</stripes:layout-component>
</stripes:layout-render>